package com.zlx.sharelive.fragment;

import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zlx.module_base.base_fg.BaseFg;
import com.zlx.sharelive.R;
import com.zlx.sharelive.adapter.CommonRecyclerViewAdapter;
import com.zlx.sharelive.adapter.CommonRecyclerViewHolder;
import com.zlx.sharelive.bean.CommunityBean;
import com.zlx.sharelive.utils.GlideImgManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 评论——图文
 */
public class CommentGraphicFg extends BaseFg {

    @BindView(R.id.rv_data)
    RecyclerView rv_data;

    private String testHeadUrl;
    private List<CommunityBean> data;
    private CommonRecyclerViewAdapter<CommunityBean> adapter;
    private CommonRecyclerViewAdapter<String> imageAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fg_long_video;
    }

    @Override
    protected void initViews() {
        super.initViews();


        initTestData();
        initRecyclerView();
    }


    /**
     * 初始化测试数据
     */
    private void initTestData() {
        testHeadUrl = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnewyx-img.hellonitrack.com%2Fm00%2F24%2F69%2F957730cc940d54eed8826fa952000b69.jpg&refer=http%3A%2F%2Fnewyx-img.hellonitrack.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642690534&t=04df6a78cff55dfcb3c9c9431b21d17f";

        data = new ArrayList<>();
        data.clear();
        for (int i = 0; i < 5; i++) {
            CommunityBean communityBean = new CommunityBean();
            List<String> urlList = new ArrayList<>();
            for (int j = 0; j < 4; j++) {
                urlList.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13925121529%2F1000.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642686222&t=6c2018187056260c44203cf559382402");
            }
            communityBean.setUrl(urlList);
            data.add(communityBean);
        }
    }

    /**
     * 初始化列表
     */
    private void initRecyclerView() {
        rv_data.setLayoutManager(new LinearLayoutManager(getContext()));

        adapter = new CommonRecyclerViewAdapter<CommunityBean>(getContext(), data) {
            @Override
            public void convert(CommonRecyclerViewHolder holder, CommunityBean entity, int position) {
                ImageView iv_community_head = holder.getView(R.id.iv_community_head);

                GlideImgManager.glideLoader(getContext(), testHeadUrl, iv_community_head, 0);

                RecyclerView rv_community_image = holder.getView(R.id.rv_community_image);

                rv_community_image.setLayoutManager(new GridLayoutManager(getContext(), 4));

                imageAdapter = new CommonRecyclerViewAdapter<String>(getContext(), entity.getUrl()) {
                    @Override
                    public void convert(CommonRecyclerViewHolder holder, String entity, int position) {
                        ImageView iv_community_image = holder.getView(R.id.iv_community_image);

                        GlideImgManager.glideLoader(getContext(), entity, iv_community_image, 1);
                    }

                    @Override
                    public int getLayoutViewId(int viewType) {
                        return R.layout.item_community_image_layout;
                    }
                };

                rv_community_image.setAdapter(imageAdapter);

            }

            @Override
            public int getLayoutViewId(int viewType) {
                return R.layout.item_community_type2;
            }
        };

        rv_data.setAdapter(adapter);
    }
}
